#ifndef DEV_CONFIG_H
#define DEV_CONFIG_H

#include <stdint.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "esp_log.h"

/* Waveshare-style typedefs */
typedef uint8_t  UBYTE;
typedef uint16_t UWORD;
typedef uint32_t UDOUBLE;

/* Pin definitions (can be overridden by -D compile definitions) */
#ifndef EPD_RST_GPIO
#define EPD_RST_GPIO 16
#endif
#ifndef EPD_DC_GPIO
#define EPD_DC_GPIO 17
#endif
#ifndef EPD_CS_GPIO
#define EPD_CS_GPIO 5
#endif
#ifndef EPD_BUSY_GPIO
#define EPD_BUSY_GPIO 4
#endif
#ifndef EPD_SCLK_GPIO
#define EPD_SCLK_GPIO 18
#endif
#ifndef EPD_MOSI_GPIO
#define EPD_MOSI_GPIO 23
#endif

/* Map to vendor pin names */
#define EPD_RST_PIN  ((UWORD)EPD_RST_GPIO)
#define EPD_DC_PIN   ((UWORD)EPD_DC_GPIO)
#define EPD_CS_PIN   ((UWORD)EPD_CS_GPIO)
#define EPD_BUSY_PIN ((UWORD)EPD_BUSY_GPIO)

/* SPI handle */
extern spi_device_handle_t DEV_SPI;

/* Module init/deinit */
int DEV_Module_Init(void);
void DEV_Module_Exit(void);

/* Digital IO */
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE DEV_Digital_Read(UWORD Pin);

/* SPI write */
void DEV_SPI_WriteByte(UBYTE data);

/* Delay */
static inline void DEV_Delay_ms(UDOUBLE xms) { vTaskDelay(pdMS_TO_TICKS(xms)); }

#endif /* DEV_CONFIG_H */
